<template>
  <div class="index-wrap">
    <Poster />
    <div class="nav-wrap">
      <div
        class="nav-item"
        v-for="item in navList"
        :key="item.key"
        :class="{ active: item.key === activeNavKey }"
        @click="chooseNav(item.key)"
      ></div>
    </div>
    <div class="form-wrap">
      <div class="form-title">{{ formTitle }}</div>
      <broad-cast class="broad-cast"/>
      <van-swipe lazy-render class="formswipe-wrap" :show-indicators="false" @change="onChange" ref="formSwipe">
        <van-swipe-item class="formswipe-item" key="1">
          <my-form :btnText="btnText" :activeNavKey="activeNavKey" @couponStatusCheck="checkCouponStatus"/>
        </van-swipe-item>
        <van-swipe-item class="formswipe-item" key="2">
          <my-form :btnText="btnText" :activeNavKey="activeNavKey" @couponStatusShow="showCouponStatus" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <van-dialog v-model="dialogVisible" confirmButtonText="知道了" confirmButtonColor="#666666" class="my-dialog">
      <div class="dialog-wrap">
        <div class="status-logo" :class="'statuslogo' + activeStatusKey"></div>
        <div class="status-value">{{ statusText }}</div>
      </div>
    </van-dialog>
  </div>
</template>
<script>
import Poster from '@/components/Poster.vue';
import BroadCast from '@/components/BroadCast.vue';
import MyForm from './components/MyForm.vue';

export default {
  name: 'index',
  computed: {
    formTitle() {
      document.title = this.activeNavKey === '1' ? '卡券兑换' : '状态查询';
      return this.activeNavKey === '1' ? '卡券兑换' : '状态查询';
    },
    btnText() {
      return this.activeNavKey === '1' ? '确认兑换' : '查询';
    },
    statusText() {
      return this.statusList.find((item) => item.key === this.activeStatusKey).name;
    },
  },
  created() {
    this.$store.commit('setCurrentCouponId', '');
  },
  mounted() {
    // 获取上一个页面跳转的传值activeStatusKey
    const { activeNavKey } = this.$route.query;
    this.activeNavKey = activeNavKey || '1';
    this.chooseNav(this.activeNavKey);
  },
  watch: {},
  components: {
    Poster,
    MyForm,
    BroadCast,
  },
  data() {
    return {
      navList: [
        {
          name: '卡券兑换',
          key: '1',
        },
        {
          name: '状态查询',
          key: '2',
        },
      ],
      activeNavKey: '1',
      dialogVisible: false,
      activeStatusKey: '1',
      statusList: [
        {
          key: '0',
          name: '未兑换',
        },
        {
          key: '1',
          name: '待发货',
        },
        {
          key: '2',
          name: '已发货',
        },
        {
          key: '3',
          name: '已签收',
        },
      ],
      broadText: '',
    };
  },
  methods: {
    checkCouponStatus() {
      this.chooseNav('2');
    },
    chooseNav(key) {
      console.log('key', key);
      this.activeNavKey = key;
      this.$refs.formSwipe.swipeTo(key - 1);
    },
    onSubmit(values) {
      console.log('submit', values);
    },
    onChange(index) {
      this.activeNavKey = `${index + 1}`;
    },
    showCouponStatus(status) {
      this.activeStatusKey = status;
      this.dialogVisible = true;
    },
  },
};
</script>
<style lang="less" scoped>
.index-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  padding-top: 30px;
  .nav-wrap {
    display: flex;
    justify-content: center;
    margin-top: 54px;
    padding: 0 30px;
    .nav-item {
      width: 394px;
      height: 120px;
      background-repeat: no-repeat;
      background-position: center;
      background-size: contain;
      &:nth-child(1) {
        background-image: url('../../assets/image/tab1.png');
        margin-right: -40px;
      }
      &:nth-child(2) {
        background-image: url('../../assets/image/tab2.png');
      }
      &.active {
        &:nth-child(1) {
          filter: drop-shadow(0 0 5px rgba(115, 112, 240, 0.2)) drop-shadow(12px 0 5px rgba(115, 112, 240, 0.2))
            drop-shadow(-12px 0 5px rgba(115, 112, 240, 0.2)) drop-shadow(0 12px 5px rgba(115, 112, 240, 0.2))
            drop-shadow(0 -12px 5px rgba(115, 112, 240, 0.2));
        }
        &:nth-child(2) {
          filter: drop-shadow(0 0 5px rgba(255, 165, 44, 0.2)) drop-shadow(12px 0 5px rgba(255, 165, 44, 0.2))
            drop-shadow(-12px 0 5px rgba(255, 165, 44, 0.2)) drop-shadow(0 12px 5px rgba(255, 165, 44, 0.2))
            drop-shadow(0 -12px 5px rgba(255, 165, 44, 0.2));
        }
      }
    }
  }
  .form-wrap {
    margin-top: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .form-title {
      font-size: 38px;
      color: #333333;
      font-weight: 500;
      margin-bottom: 40px;
      line-height: 52px;
      position: relative;
      padding: 0 5px;
      &::before {
        display: block;
        width: 100px;
        height: 6px;
        content: '';
        background-image: url('../../assets/image/line-left.png');
        background-size: 100% 100%;
        position: absolute;
        left: -116px;
        top: 23px;
      }
      &::after {
        display: block;
        content: '';
        width: 100px;
        height: 6px;
        background-image: url('../../assets/image/line-right.png');
        background-size: 100% 100%;
        position: absolute;
        right: -116px;
        top: 23px;
      }
    }
    .broad-cast {
      margin-bottom: 40px;
    }
    .formswipe-wrap::v-deep {
      width: 100%;
      .formswipe-item {
        .van-cell-group--inset {
          margin: 0 30px;
          .van-cell {
            background-color: #f8f8f8;
            border-radius: 6px;
            margin-bottom: 30px;
            height: 104px;
            padding: unset;
            display: flex;
            align-items: center;
            padding: 30px 50px;
            .van-cell__title {
              color: #131313;
              font-size: 32px;
              font-weight: 400;
              position: relative;
              width: 100px;
              &::after {
                content: '';
                display: block;
                background-image: url('../../assets/image/line-gap.png');
                background-size: 100% 100%;
                width: 2px;
                height: 44px;
                position: absolute;
                right: 0;
                top: 2px;
              }
            }
            .van-field__clear {
              font-size: 40px;
            }
            .van-field__control {
              font-size: 32px;
              font-weight: 400;
            }
          }
        }
        .van-hairline--top-bottom::after,
        .van-hairline-unset--top-bottom::after {
          display: none;
        }
      }
    }
  }
  .dialog-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 76px;
    padding-bottom: 36px;
    border-bottom: 2px solid #ededed;
    .status-logo {
      width: 176px;
      height: 176px;
      background-size: 100% 100%;
      &.statuslogo0 {
        background-image: url('../../assets/image/status4.png');
      }
      &.statuslogo1 {
        background-image: url('../../assets/image/status3.png');
      }
      &.statuslogo2 {
        background-image: url('../../assets/image/status2.png');
      }
      &.statuslogo3 {
        background-image: url('../../assets/image/status1.png');
      }
    }
    .status-value {
      margin-top: 26px;
      font-size: 32px;
      font-weight: 500;
      color: #666666;
    }
  }
  .van-dialog {
    width: 450px;
    height: 440px;
    .van-dialog__content {
      border-bottom: 2px solid #ededed;
    }
    .van-dialog__confirm {
      height: 80px;
    }
  }
}
@media (min-width: 451px) {
  .index-wrap {
    transform: scale(0.8) translateY(-12vh);
  }
}

@media (min-width: 1000px) {
  .index-wrap {
    transform: scale(0.3) translateY(-110vh);
  }
}
</style>
